package me.raih.config;

import me.raih.pojo.vo.MyHost;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Author Raih
 * @Time 2021/3/4  17:26
 *
 * 啊啊啊，配置 服务器IP地址和端口号  啊啊啊啊啊
 * 学业不精给我造成了不小的困扰
 * 成功固然是喜悦的，努力没有白费
 * 害怕的只是，即使成功了，也没有人可以分享
 */
@Configuration
public class ServerConfig{

    @Value("${spring.mail.username}")
    private String username;
    @Value("${server.port}")
    private int port;

    @Bean
    public MyHost myHost(){
        MyHost myHost = new MyHost();
        try {
            InetAddress address = InetAddress.getLocalHost();
            myHost.setHostname(address.getHostName());
            //myHost.setUsername(getUsername());
            myHost.setUsername(username);
            //myHost.setPort(getPort());
            myHost.setPort(port);
            myHost.setAddress(address.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return myHost;
    }

}
